﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Security.Cryptography;

namespace PowerTest
{
    class Func
    {
        public static string maTruyCap = "admin", tenTruyCap = "Vũ Hoàng Lâm", matKhau = "admin";
        public static string phanQuyen = "4";
        public static string h, p, s, d, m, y;              
        public static void hpsdmy()
        {
            if (DateTime.Now.Hour < 10)
            {
                h = "0" + DateTime.Now.Hour.ToString();
            }
            else
            {
                h = DateTime.Now.Hour.ToString();
            }
            if (DateTime.Now.Minute < 10)
            {
                p = "0" + DateTime.Now.Minute.ToString();
            }
            else
            {
                p = DateTime.Now.Minute.ToString();
            }

            if (DateTime.Now.Second < 10)
            {
                s = "0" + DateTime.Now.Second.ToString();
            }
            else
            {
                s = DateTime.Now.Second.ToString();
            }
            if (DateTime.Now.Day < 10)
            {
                d = "0" + DateTime.Now.Day.ToString();
            }
            else
            {
                d = DateTime.Now.Day.ToString();
            }
            if (DateTime.Now.Month < 10)
            {
                m = "0" + DateTime.Now.Month.ToString();
            }
            else
            {
                m = DateTime.Now.Month.ToString();
            }
            y = DateTime.Now.Year.ToString();
        }
        private static string autoThoiGian()
        {
            return "-" + y + "-" + m + "-" + d + "/" + h + "-"
                + p + "-" + s + "-"
                + DateTime.Now.Millisecond.ToString();
        }
        public static void NhapSo(Object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            if (Char.IsControl(e.KeyChar) || Char.IsDigit(e.KeyChar))
            {
            }
            else
            {
                e.Handled = true;
            }
        }
        /*public static DataTable getData(string sql)
        {
            DataSet ds = new DataSet();
            SqlConnection con = new SqlConnection();
            con.ConnectionString = PowerTest.Properties
                .Settings.Default.DevicesConnectionString.ToString();
            SqlCommand conn = con.CreateCommand();
            conn.CommandText = sql;
            conn.CommandType = CommandType.Text;
            new SqlDataAdapter(conn).Fill(ds);
            return ds.Tables[0];
        }*/
        public static void Check(RadioButton rb, GroupBox gb)
        {
            if (rb.Checked == true)
            {
                gb.Enabled = true;
            }
            else
            {
                gb.Enabled = false;
            }
        }
        public static string autoMSSV()
        {
            return y + m + d + h + p + s;
        }
        public static string autoMCH()
        {
            return "MCH" + y + m + d + h + p + s;
        }
        public static string autoDeThi()
        {
            return "DeThi" + y + m + d + h + p + s;
        }
        public static string autoMaCTDe()
        {
            return "CTDe" + y + m + d + h + p + s;
        }
        /*
        public static string MaHoa(string a)
        {
            SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
            byte[] bs = Encoding.UTF8.GetBytes(a);
            bs = sha1.ComputeHash(bs);
            StringBuilder sb = new StringBuilder();
            foreach (byte b in bs)
            {
                sb.Append(b.ToString("x2").ToLower());
            }
            return sb.ToString().ToUpper();
        }*/
    }
}
